#ifndef DIALOG_H
#define DIALOG_H

#include <QListWidget>
#include <QMainWindow>
#include <QQueue>
#include <QCheckBox>
#include <QStackedWidget>
#include <QRadioButton>


QT_BEGIN_NAMESPACE
class QComboBox;
class QDialogButtonBox;
class QGridLayout;
class QGroupBox;
class QLabel;
class QPushButton;
class QSpinBox;
class QLineEdit;
class QTabWidget;
class Dialog;
class Register;
class MainWindow;
class QStackWidget;
QT_END_NAMESPACE

/** Class Dialog. Represents the content of the main window. Inherits from the QT class QWidget.
    When a new file is opened or created, a new Dialog class is built and the old one is destroyed.*/
class Dialog : public QWidget
{
    Q_OBJECT

public:
    Dialog(QWidget *parent = 0);

    QQueue<Register *>* getRegisters(){return &registers;};
    QListWidget* getRegListWidget(){return regListWidget;};
    QString getBaseAddr();
    void generateXML(QString filename);
    void readXML(QString filename);
    bool read(QIODevice *device);
    bool isModified(){return isMod;};
    Qt::LayoutDirection getNotation(){if(leftToRight->isChecked())return Qt::LeftToRight; else return Qt::RightToLeft;};

    void isSaved();
    MainWindow* getWindow(){return bigWindow;};
    void setWindow(MainWindow* w){bigWindow=w;};



public slots:
    void hasChanged();

private slots:
    void generateCode();
    void addRegister(bool autoAssign=true);
    void changeReg(QListWidgetItem *current, QListWidgetItem *previous);
    void changeEndian(bool b);
    void changeNotation(bool b);


private:
    void createDeviceGroupBox();
    void createButtonBox();




    bool isMod;
    int devBits;

    //! Pointer to the register currently selected and displayed
    Register *registerBox;

    //! Pointer to the parent MainWindow
    MainWindow *bigWindow;

    QGroupBox *deviceGroupBox;
    QLabel    *devNameLabel;
    QLabel    *bitsLabel;
    QLabel    *regListLabel;
    QLabel    *baseAddrLabel;

    QPushButton *addRegButton;
    QPushButton *generateCodeButton;

    QLineEdit *deviceName;
    QLineEdit *baseAddr;
    
    QButtonGroup *endianness;
    QRadioButton *bigEndian;
    QRadioButton *littleEndian;

    QButtonGroup *notation;
    QRadioButton *leftToRight;
    QRadioButton *rightToLeft;


    QGridLayout *mainLayout;
    QGridLayout *optionsLayout;

    //! List of the registers in the layout
    QQueue<Register *> registers;

    //! QWidget displaying a list of the registers
    QListWidget *regListWidget;

};




#endif
